/**
 * 报警日志管理初始化
 */
var DoorAlarmRecord = {
    id: "DoorAlarmRecordTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
DoorAlarmRecord.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '', field: 'id', visible: true, align: 'center', valign: 'middle'},
        {title: '名称', field: 'name', visible: true, align: 'center', valign: 'middle'},
        {title: '卡号', field: 'cardno', visible: true, align: 'center', valign: 'middle'},
        {title: '开门状态', field: 'openDoorStatus', visible: true, align: 'center', valign: 'middle'},
        {title: '门号', field: 'doorNumber', visible: true, align: 'center', valign: 'middle'},
        {title: '进出', field: 'inOut', visible: true, align: 'center', valign: 'middle'},
        {title: '刷卡时间', field: 'time', visible: true, align: 'center', valign: 'middle'},
        {title: '打卡次数', field: 'note1', visible: true, align: 'center', valign: 'middle'},
        /*  {title: '预留字段2', field: 'note2', visible: true, align: 'center', valign: 'middle'}*/
    ];
};

/**
 * 检查是否选中
 */
DoorAlarmRecord.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        DoorAlarmRecord.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加报警日志
 */
DoorAlarmRecord.openAddDoorAlarmRecord = function () {
    var index = layer.open({
        type: 2,
        title: '添加报警日志',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doorAlarmRecord/doorAlarmRecord_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看报警日志详情
 */
DoorAlarmRecord.openDoorAlarmRecordDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '报警日志详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/doorAlarmRecord/doorAlarmRecord_update/' + DoorAlarmRecord.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除报警日志
 */
DoorAlarmRecord.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/doorAlarmRecord/delete", function (data) {
            Feng.success("删除成功!");
            DoorAlarmRecord.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("doorAlarmRecordId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询报警日志列表
 */
DoorAlarmRecord.search = function () {

    var queryData = {};
    queryData['name'] = $("#name").val();
    queryData['cardNo'] = $("#cardNo").val();
    queryData['status'] = $("#status").val();
    queryData['doorNumber'] = $("#doorNumber").val();
    queryData['inOrGo'] = $("#inOrGo").val();
    queryData['beginTime'] = $("#beginTime").val();
    queryData['endTime'] = $("#endTime").val();

    DoorAlarmRecord.table.refresh({query: queryData});
};
/**
 * 下载报警日志列表
 * */
DoorAlarmRecord.download=function(){
    window.location.href="/doorAlarmRecord/download";

}

/**
 * 清空
 */
DoorAlarmRecord.deleteAll = function () {
    $.ajax({
        url: Feng.ctxPath +"/doorAlarmRecord/deleteAll",//获取数据的URL
        type: "Post",//HTTP请求方法
        async: false,
        success: function (data) {
            Feng.success("删除成功!");
            DoorAlarmRecord.table.refresh();
        },
        error:function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        }
    });
};

$(function () {
    var defaultColunms = DoorAlarmRecord.initColumn();
    var table = new BSTable(DoorAlarmRecord.id, "/doorAlarmRecord/list", defaultColunms);
    table.setPaginationType("client");
    DoorAlarmRecord.table = table.init();
});
